/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of UHM (Unassembled HyperMatrix) sparse direct solver.
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#ifndef UHM_MATRIX_UHM_HELPER_HXX
#define UHM_MATRIX_UHM_HELPER_HXX

namespace uhm {
  // --------------------------------------------------------------
  typedef class  Helper_* Helper;
  typedef class  Element_* Element;
  typedef struct Mapper_* Mapper;
  typedef struct Mapper_* Mapper;

  struct Mapper_ { int offs_c, offs_p, fs_p, n_dof; };

  // ** Helper matrix
  class Helper_ {
  protected:
    int     cookie;
    Element p, c;

    std::vector<Mapper_> mapper;

    void _merge_A    ();
    void _branch_ABR ();

    void _merge_rhs  (int kind, int is_pivot_applied);
    void _branch_rhs (int kind);

    int  _get_rhs    (int col);
    int  _get_A      (int col, int row);

  public:
    Helper_();
    Helper_(Element p, Element c);
    virtual ~Helper_();

    bool disp();
    bool disp(FILE *stream);

    void set_mapper();

    void merge_A();
    void branch_ABR();

    void merge_rhs_x();
    void merge_rhs_b();
    void merge_rhs_r();

    void branch_rhs_x();
    void branch_rhs_b();
    void branch_rhs_r();
  };

}


#endif
